Visualising French postal code data in Jupyter lab¶

This is intended to provide a better understanding of the shape file contents in order to determine if it is fit for intended purpose.

The original shape file was sourced from here:

https://www.data.gouv.fr/en/datasets/fond-de-carte-des-codes-postaux/#/resources/029656d6-0fcd-48ec-917d-d511e1f36ff6

Download the zip file at that location and extract to local project directory.

Import dependencies¶

In [1]:
import geopandas

Read the shapefile content¶

In [4]:
shape_file_src = 'codes_postaux_V5/codes_postaux_region.shp'
gdf = geopandas.read_file(shape_file_src)

Check the type assigned to gdf variable¶

In [5]:
type(gdf)
Out[5]:
geopandas.geodataframe.GeoDataFrame

Inspect the shape (rows, colums)¶

In [7]:
gdf.shape
Out[7]:
(6048, 7)

Show the first few rows of data¶

In [6]:
gdf.head()
Out[6]:
ID LIB DEP SURF POP2010 MEN2010 geometry
0 26140 Saint-Rambert-d'Albon 26 82.710226 12812.0 5148.08200 POLYGON ((849939.960 6461152.035, 848364.990 6...
1 26150 Die 26 315.349961 6301.0 3011.68790 POLYGON ((892450.050 6403419.960, 891173.040 6...
2 26160 La Bégude-de-Mazenc 26 181.940199 7285.0 3040.83720 POLYGON ((862423.980 6386618.040, 861627.030 6...
3 26300 Bourg-de-Péage 26 236.697761 28064.0 11312.93600 POLYGON ((873008.010 6428766.990, 872238.960 6...
4 26170 Buis-les-Baronnies 26 290.688573 5512.0 2543.62744 POLYGON ((899364.960 6353489.025, 897448.020 6...

Draw a map as an image¶

In [9]:
gdf.plot(cmap='rainbow')
Out[9]:
<Axes: >
No description has been provided for this image

Explore an interactive map¶

In [13]:
gdf.explore("ID", cmap="rainbow", legend=False)
Out[13]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Draw only specific region/shape¶

In [14]:
paris_shape = gdf[gdf['DEP'] == '75']
paris_shape.plot()
Out[14]:
<Axes: >
No description has been provided for this image

Interact with the Paris region¶

In [16]:
paris_shape.explore()
Out[16]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Convert the original shape file to geojson format¶

Not necessary, but could be useful.

In [18]:
gdf.to_file('codes_postaux_region.geojson', driver='GeoJSON')